--- title: "L2-009 抢红包" created: 2025-11-28 tags: - 算法 --- # L2-009 抢红包 ## 题目 [L2-009 抢红包](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=994805066890854400&page=1) ![[image-d9b7b186.png]] ## 思路分析 ![[image-a4863908.png]] ## 代码实现 ```cpp #include using namespace std; #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; const int inf = 0x3f3f3f3f; struct Person{ int id; double income; int cnt; bool operator<(const Person& rhs) const{ if(income != rhs.income) return income>rhs.income; if(cnt != rhs.cnt) return cnt>rhs.cnt; return id>n; vector income(n+1,0); vector cnt(n+1,0); for(int i=1;i<=n;i++){ cin>>k; int total=0; for(int j=0;j>receiver>>money; income[i]-=money; income[receiver]+=money; cnt[receiver]++; } } vector res; for(int i=1;i<=n;i++){ res.push_back({i,income[i]*1.0/100,cnt[i]}); } sort(res.begin(),res.end()); for(auto p:res){ printf("%d %.2f\n",p.id,p.income); } return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[L2-008 最长对称子串|L2-008 最长对称子串]] 🏠 [[00-天梯赛]] ➡️ [[L2-010 排座位|L2-010 排座位]]